/*
 * YearConsumeFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package com.insigma.yanwenlong.bookkeeping.gui;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.sql.SQLException;
import java.util.List;

import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;

import com.insigma.yanwenlong.bookkeeping.pojo.Account;
import com.insigma.yanwenlong.bookkeeping.pojo.Category;
import com.insigma.yanwenlong.bookkeeping.pojo.Member;
import com.insigma.yanwenlong.bookkeeping.pojo.YearConsume;
import com.insigma.yanwenlong.bookkeeping.pojo.YearConsumeCondition;
import com.insigma.yanwenlong.bookkeeping.service.AccountService;
import com.insigma.yanwenlong.bookkeeping.service.AccountServiceImpl;
import com.insigma.yanwenlong.bookkeeping.service.CategoryService;
import com.insigma.yanwenlong.bookkeeping.service.CategoryServiceImpl;
import com.insigma.yanwenlong.bookkeeping.service.DetailService;
import com.insigma.yanwenlong.bookkeeping.service.DetailServiceImpl;
import com.insigma.yanwenlong.bookkeeping.service.MemberService;
import com.insigma.yanwenlong.bookkeeping.service.MemberServiceImpl;
import com.insigma.yanwenlong.bookkeeping.service.YearConsumeService;
import com.insigma.yanwenlong.bookkeeping.service.YearConsumeServiceImpl;

/**
 *
 * @author  __USER__
 */
public class YearConsumeFrame extends javax.swing.JFrame {
	private AccountService accountService = new AccountServiceImpl();
	private MemberService memberService = new MemberServiceImpl();
	private CategoryService categoryService = new CategoryServiceImpl();
	private YearConsumeService yearConsumeService = new YearConsumeServiceImpl();
	private DetailService detailService = new DetailServiceImpl();
	private DefaultTableModel dtm;

	/** Creates new form YearConsumeFrame */
	public YearConsumeFrame() {
		this.setTitle("年度收支表");
		initComponents();
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		//初始化界面数据
		initData();
	}

	private void initData() {
		// 初始账户
		initAccount();
		//初始家庭成员
		initMember();
		//初始年度
		initYear();
		//初始表格中的数据
		initJtableData();

	}

	private void initJtableData() {
		Category category = null;
		try {
			List<YearConsume> yearConsumes = yearConsumeService
					.findAllYearConsume();
			dtm = (DefaultTableModel) tblYearConsume.getModel();
			//添加收入数据
			dtm.addRow(new Object[] { "收入", "", "", "", "", "", "", "", "", "",
					"", "", "", "" });
			double month1InTotal = 0, month2InTotal = 0, month3InTotal = 0, month4InTotal = 0;
			double month5InTotal = 0, month6InTotal = 0, month7InTotal = 0, month8InTotal = 0;
			double month9InTotal = 0, month10InTotal = 0, month11InTotal = 0, month12InTotal = 0;
			for (YearConsume yearConsume : yearConsumes) {
				category = categoryService.findDirectionIdById(yearConsume
						.getCategoryId());
				if (category.getDirectionId() == 2) {
					month1InTotal += yearConsume.getMonth1();
					month2InTotal += yearConsume.getMonth2();
					month3InTotal += yearConsume.getMonth3();
					month4InTotal += yearConsume.getMonth4();
					month5InTotal += yearConsume.getMonth5();
					month6InTotal += yearConsume.getMonth6();
					month7InTotal += yearConsume.getMonth7();
					month8InTotal += yearConsume.getMonth8();
					month9InTotal += yearConsume.getMonth9();
					month10InTotal += yearConsume.getMonth10();
					month11InTotal += yearConsume.getMonth11();
					month12InTotal += yearConsume.getMonth12();
					dtm.addRow(new Object[] {
							category.getCategoryName(),
							yearConsume.getMonth1(),
							yearConsume.getMonth2(),
							yearConsume.getMonth3(),
							yearConsume.getMonth4(),
							yearConsume.getMonth5(),
							yearConsume.getMonth6(),
							yearConsume.getMonth7(),
							yearConsume.getMonth8(),
							yearConsume.getMonth9(),
							yearConsume.getMonth10(),
							yearConsume.getMonth11(),
							yearConsume.getMonth12(),

							yearConsume.getMonth1() + yearConsume.getMonth2()
									+ yearConsume.getMonth3()
									+ yearConsume.getMonth4()
									+ yearConsume.getMonth5()
									+ yearConsume.getMonth6()
									+ yearConsume.getMonth7()
									+ yearConsume.getMonth8()
									+ yearConsume.getMonth9()
									+ yearConsume.getMonth10()
									+ yearConsume.getMonth11()
									+ yearConsume.getMonth12() });
				}

			}
			double incomeTotal = month1InTotal + month2InTotal + month3InTotal
					+ month4InTotal + month5InTotal + month6InTotal
					+ month7InTotal + month8InTotal + month9InTotal
					+ month10InTotal + month11InTotal + month12InTotal;
			dtm
					.addRow(new Object[] { "收入小计:", month1InTotal,
							month2InTotal, month3InTotal, month4InTotal,
							month5InTotal, month6InTotal, month7InTotal,
							month8InTotal, month9InTotal, month10InTotal,
							month11InTotal, month12InTotal, incomeTotal });

			//添加支出数据
			dtm.addRow(new Object[] { "支出", "", "", "", "", "", "", "", "", "",
					"", "", "", "" });
			double month1OutTotal = 0, month2OutTotal = 0, month3OutTotal = 0, month4OutTotal = 0;
			double month5OutTotal = 0, month6OutTotal = 0, month7OutTotal = 0, month8OutTotal = 0;
			double month9OutTotal = 0, month10OutTotal = 0, month11OutTotal = 0, month12OutTotal = 0;
			for (YearConsume yearConsume : yearConsumes) {
				category = categoryService.findDirectionIdById(yearConsume
						.getCategoryId());
				if (category.getDirectionId() == 1) {
					month1OutTotal += yearConsume.getMonth1();
					month2OutTotal += yearConsume.getMonth2();
					month3OutTotal += yearConsume.getMonth3();
					month4OutTotal += yearConsume.getMonth4();
					month5OutTotal += yearConsume.getMonth5();
					month6OutTotal += yearConsume.getMonth6();
					month7OutTotal += yearConsume.getMonth7();
					month8OutTotal += yearConsume.getMonth8();
					month9OutTotal += yearConsume.getMonth9();
					month10OutTotal += yearConsume.getMonth10();
					month11OutTotal += yearConsume.getMonth11();
					month12OutTotal += yearConsume.getMonth12();
					dtm.addRow(new Object[] {
							category.getCategoryName(),
							yearConsume.getMonth1(),
							yearConsume.getMonth2(),
							yearConsume.getMonth3(),
							yearConsume.getMonth4(),
							yearConsume.getMonth5(),
							yearConsume.getMonth6(),
							yearConsume.getMonth7(),
							yearConsume.getMonth8(),
							yearConsume.getMonth9(),
							yearConsume.getMonth10(),
							yearConsume.getMonth11(),
							yearConsume.getMonth12(),

							yearConsume.getMonth1() + yearConsume.getMonth2()
									+ yearConsume.getMonth3()
									+ yearConsume.getMonth4()
									+ yearConsume.getMonth5()
									+ yearConsume.getMonth6()
									+ yearConsume.getMonth7()
									+ yearConsume.getMonth8()
									+ yearConsume.getMonth9()
									+ yearConsume.getMonth10()
									+ yearConsume.getMonth11()
									+ yearConsume.getMonth12() });
				}

			}
			double outcomeTotal = month1OutTotal + month2OutTotal
					+ month3OutTotal + month4OutTotal + month5OutTotal
					+ month6OutTotal + month7OutTotal + month8OutTotal
					+ month9OutTotal + month10OutTotal + month11OutTotal
					+ month12OutTotal;
			dtm.addRow(new Object[] { "支出小计:", month1OutTotal, month2OutTotal,
					month3OutTotal, month4OutTotal, month5OutTotal,
					month6OutTotal, month7OutTotal, month8OutTotal,
					month9OutTotal, month10OutTotal, month11OutTotal,
					month12OutTotal, outcomeTotal });

			//添加总合计
			dtm.addRow(new Object[] { "总合计:", month1InTotal - month1OutTotal,
					month2InTotal - month2OutTotal,
					month3InTotal - month3OutTotal,
					month4InTotal - month4OutTotal,
					month5InTotal - month5OutTotal,
					month6InTotal - month6OutTotal,
					month7InTotal - month7OutTotal,
					month8InTotal - month8OutTotal,
					month9InTotal - month9OutTotal,
					month10InTotal - month10OutTotal,
					month11InTotal - month11OutTotal,
					month12InTotal - month12OutTotal,
					incomeTotal - outcomeTotal });
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	private void initYear() {
		DefaultComboBoxModel dcbm = (DefaultComboBoxModel) cobYear.getModel();
		for (int i = 2010; i < 2031; i++) {
			dcbm.addElement(i);
		}
	}

	private void initMember() {
		try {
			List<Member> members = memberService.findallMembers();
			DefaultComboBoxModel dcbm = (DefaultComboBoxModel) cobMember
					.getModel();
			for (Member member : members) {
				dcbm.addElement(member);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	private void initAccount() {
		try {
			List<Account> accounts = accountService.findaAccounts();
			DefaultComboBoxModel dcbm = (DefaultComboBoxModel) cobAccount
					.getModel();
			for (Account account : accounts) {
				dcbm.addElement(account);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		tblYearConsume = new javax.swing.JTable();
		cobAccount = new javax.swing.JComboBox();
		cobYear = new javax.swing.JComboBox();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		cobMember = new javax.swing.JComboBox();
		spnBeginMoney = new javax.swing.JSpinner();
		spnEndMoney = new javax.swing.JSpinner();
		btnSearch = new javax.swing.JButton();
		btnExport = new javax.swing.JButton();
		jLabel4 = new javax.swing.JLabel();
		jLabel5 = new javax.swing.JLabel();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jLabel1.setText("\u8d26\u6237");

		tblYearConsume.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] {

				}, new String[] { "类别", "1月", "2月", "3月", "4月", "5月", "6月",
						"7月", "8月", "9月", "10月", "11月", "12月", "全年" }) {
			boolean[] canEdit = new boolean[] { false, false, false, false,
					false, false, false, false, false, false, false, false,
					false, false };

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		jScrollPane1.setViewportView(tblYearConsume);

		cobAccount.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "请选择" }));

		jLabel2.setText("\u5e74\u5ea6");

		jLabel3.setText("\u5bb6\u5ead\u6210\u5458");

		cobMember.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "请选择" }));

		spnBeginMoney.setModel(new javax.swing.SpinnerNumberModel(Double
				.valueOf(0.0d), Double.valueOf(0.0d), null, Double
				.valueOf(1.0d)));

		spnEndMoney.setModel(new javax.swing.SpinnerNumberModel(Double
				.valueOf(0.0d), Double.valueOf(0.0d), null, Double
				.valueOf(1.0d)));

		btnSearch.setText("\u67e5\u8be2");
		btnSearch.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnSearchActionPerformed(evt);
			}
		});

		btnExport.setText("\u5bfc\u51fa");
		btnExport.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnExportActionPerformed(evt);
			}
		});

		jLabel4.setText("\u91d1\u989d\u4ece");

		jLabel5.setText("\u5230");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addComponent(
																				jLabel1)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				cobAccount,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				85,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																layout
																		.createSequentialGroup()
																		.addComponent(
																				jLabel4)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)
																		.addComponent(
																				spnBeginMoney,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				82,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																layout
																		.createSequentialGroup()
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				jLabel2)
																		.addGap(
																				6,
																				6,
																				6)
																		.addComponent(
																				cobYear,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				73,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																layout
																		.createSequentialGroup()
																		.addGap(
																				1,
																				1,
																				1)
																		.addComponent(
																				jLabel5)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				spnEndMoney,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				82,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addComponent(
																				jLabel3)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				cobMember,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				82,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addComponent(
																				btnSearch)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				btnExport)))
										.addContainerGap(322, Short.MAX_VALUE))
						.addComponent(jScrollPane1,
								javax.swing.GroupLayout.DEFAULT_SIZE, 713,
								Short.MAX_VALUE));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel1)
														.addComponent(
																cobAccount,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel2)
														.addComponent(
																cobYear,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel3)
														.addComponent(
																cobMember,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(18, 18, 18)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(btnSearch)
														.addComponent(btnExport)
														.addComponent(jLabel4)
														.addComponent(
																spnBeginMoney,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel5)
														.addComponent(
																spnEndMoney,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(
												jScrollPane1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												208,
												javax.swing.GroupLayout.PREFERRED_SIZE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents
	
	//点击查询，在页面上显示账务年度信息
	private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {
		int accountId = -1;
		if(cobAccount.getSelectedItem() instanceof Account) {
			Account account = (Account)cobAccount.getSelectedItem();
			accountId = account.getId();
		}
		
		int year = (Integer)cobYear.getSelectedItem();
		
		int memberId = -1;
		if(cobMember.getSelectedItem() instanceof Member) {
			Member member = (Member)cobMember.getSelectedItem();
			memberId = member.getId();
		}
		
		double beginMoney = (Double)spnBeginMoney.getValue();
		double endMoney = (Double)spnEndMoney.getValue();
		
		YearConsumeCondition ycc = new YearConsumeCondition();
		ycc.setAccountId(accountId);
		ycc.setBeginMoney(beginMoney);
		ycc.setEndMoney(endMoney);
		ycc.setMemberId(memberId);
		ycc.setYear(year);
		
		initYearConsume(ycc);
	}

	private void initYearConsume(YearConsumeCondition ycc) {
		Category category = null;
		try {
			List<YearConsumeCondition> yccs = detailService.findYearConsumeConditions(ycc);
			dtm = (DefaultTableModel) tblYearConsume.getModel();
			//清空表中原来的数据
			dtm.setRowCount(0);
			//添加收入数据
			dtm.addRow(new Object[] { "收入", "", "", "", "", "", "", "", "", "",
					"", "", "", "" });
			double month1InTotal = 0, month2InTotal = 0, month3InTotal = 0, month4InTotal = 0;
			double month5InTotal = 0, month6InTotal = 0, month7InTotal = 0, month8InTotal = 0;
			double month9InTotal = 0, month10InTotal = 0, month11InTotal = 0, month12InTotal = 0;
			for (YearConsumeCondition ycc1 : yccs) {
				category = categoryService.findDirectionIdById(ycc1
						.getCategoryId());
				if (category.getDirectionId() == 2) {
					month1InTotal += ycc1.getMonth1();
					month2InTotal += ycc1.getMonth2();
					month3InTotal += ycc1.getMonth3();
					month4InTotal += ycc1.getMonth4();
					month5InTotal += ycc1.getMonth5();
					month6InTotal += ycc1.getMonth6();
					month7InTotal += ycc1.getMonth7();
					month8InTotal += ycc1.getMonth8();
					month9InTotal += ycc1.getMonth9();
					month10InTotal += ycc1.getMonth10();
					month11InTotal += ycc1.getMonth11();
					month12InTotal += ycc1.getMonth12();
					dtm.addRow(new Object[] {
							category.getCategoryName(),
							ycc1.getMonth1(),
							ycc1.getMonth2(),
							ycc1.getMonth3(),
							ycc1.getMonth4(),
							ycc1.getMonth5(),
							ycc1.getMonth6(),
							ycc1.getMonth7(),
							ycc1.getMonth8(),
							ycc1.getMonth9(),
							ycc1.getMonth10(),
							ycc1.getMonth11(),
							ycc1.getMonth12(),

							ycc1.getMonth1() + ycc1.getMonth2()
									+ ycc1.getMonth3()
									+ ycc1.getMonth4()
									+ ycc1.getMonth5()
									+ ycc1.getMonth6()
									+ ycc1.getMonth7()
									+ ycc1.getMonth8()
									+ ycc1.getMonth9()
									+ ycc1.getMonth10()
									+ ycc1.getMonth11()
									+ ycc1.getMonth12() });
				}

			}
			double incomeTotal = month1InTotal + month2InTotal + month3InTotal
					+ month4InTotal + month5InTotal + month6InTotal
					+ month7InTotal + month8InTotal + month9InTotal
					+ month10InTotal + month11InTotal + month12InTotal;
			dtm
					.addRow(new Object[] { "收入小计:", month1InTotal,
							month2InTotal, month3InTotal, month4InTotal,
							month5InTotal, month6InTotal, month7InTotal,
							month8InTotal, month9InTotal, month10InTotal,
							month11InTotal, month12InTotal, incomeTotal });

			//添加支出数据
			dtm.addRow(new Object[] { "支出", "", "", "", "", "", "", "", "", "",
					"", "", "", "" });
			double month1OutTotal = 0, month2OutTotal = 0, month3OutTotal = 0, month4OutTotal = 0;
			double month5OutTotal = 0, month6OutTotal = 0, month7OutTotal = 0, month8OutTotal = 0;
			double month9OutTotal = 0, month10OutTotal = 0, month11OutTotal = 0, month12OutTotal = 0;
			for (YearConsumeCondition ycc1 : yccs) {
				category = categoryService.findDirectionIdById(ycc1
						.getCategoryId());
				if (category.getDirectionId() == 1) {
					month1OutTotal += ycc1.getMonth1();
					month2OutTotal += ycc1.getMonth2();
					month3OutTotal += ycc1.getMonth3();
					month4OutTotal += ycc1.getMonth4();
					month5OutTotal += ycc1.getMonth5();
					month6OutTotal += ycc1.getMonth6();
					month7OutTotal += ycc1.getMonth7();
					month8OutTotal += ycc1.getMonth8();
					month9OutTotal += ycc1.getMonth9();
					month10OutTotal += ycc1.getMonth10();
					month11OutTotal += ycc1.getMonth11();
					month12OutTotal += ycc1.getMonth12();
					dtm.addRow(new Object[] {
							category.getCategoryName(),
							ycc1.getMonth1(),
							ycc1.getMonth2(),
							ycc1.getMonth3(),
							ycc1.getMonth4(),
							ycc1.getMonth5(),
							ycc1.getMonth6(),
							ycc1.getMonth7(),
							ycc1.getMonth8(),
							ycc1.getMonth9(),
							ycc1.getMonth10(),
							ycc1.getMonth11(),
							ycc1.getMonth12(),

							ycc1.getMonth1() + ycc1.getMonth2()
									+ ycc1.getMonth3()
									+ ycc1.getMonth4()
									+ ycc1.getMonth5()
									+ ycc1.getMonth6()
									+ ycc1.getMonth7()
									+ ycc1.getMonth8()
									+ ycc1.getMonth9()
									+ ycc1.getMonth10()
									+ ycc1.getMonth11()
									+ ycc1.getMonth12() });
				}

			}
			double outcomeTotal = month1OutTotal + month2OutTotal
					+ month3OutTotal + month4OutTotal + month5OutTotal
					+ month6OutTotal + month7OutTotal + month8OutTotal
					+ month9OutTotal + month10OutTotal + month11OutTotal
					+ month12OutTotal;
			dtm.addRow(new Object[] { "支出小计:", month1OutTotal, month2OutTotal,
					month3OutTotal, month4OutTotal, month5OutTotal,
					month6OutTotal, month7OutTotal, month8OutTotal,
					month9OutTotal, month10OutTotal, month11OutTotal,
					month12OutTotal, outcomeTotal });

			//添加总合计
			dtm.addRow(new Object[] { "总合计:", month1InTotal - month1OutTotal,
					month2InTotal - month2OutTotal,
					month3InTotal - month3OutTotal,
					month4InTotal - month4OutTotal,
					month5InTotal - month5OutTotal,
					month6InTotal - month6OutTotal,
					month7InTotal - month7OutTotal,
					month8InTotal - month8OutTotal,
					month9InTotal - month9OutTotal,
					month10InTotal - month10OutTotal,
					month11InTotal - month11OutTotal,
					month12InTotal - month12OutTotal,
					incomeTotal - outcomeTotal });
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	//点击导出
	private void btnExportActionPerformed(java.awt.event.ActionEvent evt) {
		int row = dtm.getRowCount();
		int column = dtm.getColumnCount();
		String[] information = new String[row];
		for (int i = 0; i < row; i++) {
			information[i] = "";
			for (int j = 0; j < column; j++) {
				information[i] += dtm.getValueAt(i, j) + "\t";
			}
			information[i] += "\n";
		}
		File file = new File("D:/年度收支信息.txt");
		OutputStreamWriter osw = null;
		String s = null;
		try {
			osw = new OutputStreamWriter(new FileOutputStream(file));
			for (int index = 0; index < row; index++) {
				try {
					s = information[index].replace("\n", "\r\n");
					osw.write(s);
					osw.flush();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			try {
				osw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new YearConsumeFrame().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton btnExport;
	private javax.swing.JButton btnSearch;
	private javax.swing.JComboBox cobAccount;
	private javax.swing.JComboBox cobMember;
	private javax.swing.JComboBox cobYear;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JSpinner spnBeginMoney;
	private javax.swing.JSpinner spnEndMoney;
	private javax.swing.JTable tblYearConsume;
	// End of variables declaration//GEN-END:variables

}